const http=require('http');
const fs=require('fs');
const server=http.createServer(function(req,res){
    //console.log(req.url,req.method);
    if(req.url==='/home'){
        res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'});
        res.end('<h1>这是首页</h1>')
    }
    if(req.url==='/user'){
        const data=fs.readFileSync('./db.json','utf-8')
        console.log(data);
        res.writeHead(200,{'Content-Type':'application/json;charset=utf-8'});
        res.end(data)
    }
})
server.listen(3000,()=>{
    console.log('server is listening on port 3000');
});